package com.ht.aems.fesmodel;

import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2009-5-23
 */
public class UnitManagerUtil {
    public static void getAllDevices(IUnitManager m, List<CommUnit> v) {
        for (String key : m.getAllUnits().keySet()) {
            Object obj = m.getAllUnits().get(key);
            if (obj instanceof CommUnit)
                v.add((CommUnit) obj);
            else if (obj instanceof IUnitManager)
                getAllDevices((IUnitManager) obj, v);
        }
    }

    public static int getDeviceNum(IUnitManager m) {
        int counter = 0;
        Map map = m.getAllUnits();
        for (Object key : map.keySet()) {
            Object obj = map.get(key);
            if (obj instanceof CommUnit)
                counter++;
            else if (map.get(key) instanceof IUnitManager)
                counter += getDeviceNum((IUnitManager) obj);
        }
        return counter;
    }
}
